home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_091 / adlrun / adlscrn.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  240 lines

  1.     /***************************************************************\
  2.     *                                *
  3.     *    adlscrn.c - Screen I/O for adlrun.  Add new def's    *
  4.     *    for a new terminal here (unless using termcap).        *
  5.     *                                *
  6.     \***************************************************************/
  7.  
  8. #include <stdio.h>
  9.  
  10. #include "adltypes.h"
  11. #include "adlprog.h"
  12. #include "adldef.h"
  13. #include "adlrun.h"
  14. #include "vstring.h"
  15.  
  16.  
  17. #if HPTERM
  18. static char
  19.     TGOTO[]    = "\033&a%dy%dC",
  20.     CLEAR[]    = "\033J",
  21.     STANDOUT[]    = "\033&dJ",
  22.     STANDEND[]    = "",
  23.     LOCK[]    = "\033l",
  24.     NOLOCK[]    = "\033m";
  25. #endif
  26.  
  27. #if ANSI
  28. static char
  29.     TGOTO[]    = "\033[%02d;%02dH",
  30.     CLEAR[]    = "\014",
  31.     STANDOUT[]    = "\033[0;7m",
  32.     STANDEND[]    = "\033[0m",
  33.     LOCK[]    = "",
  34.     NOLOCK[]    = "";
  35. #endif
  36.  
  37. #if TERMCAP
  38. char
  39.     *BC, *UP;        /* Just to satisfy the linker */
  40.  
  41. static char
  42.     BUFF[1024],        /* Buffer for tgetent */
  43.     TGOTO[20],        /* cm        */
  44.     CLEAR[10],        /* cd        */
  45.     STANDOUT[10],    /* so        */
  46.     STANDEND[10],    /* se        */
  47.     LOCK[10],        /* ml        */
  48.     NOLOCK[10];        /* mu        */
  49. #endif
  50.  
  51. static int
  52.     END = -1;        /* Last line on the screen */
  53.  
  54. #if AMIGA == 0
  55. char
  56.     *getenv();        /* Find an environment variable */
  57. #endif
  58.  
  59. head_setup()
  60. {
  61.     char
  62.     *value;        /* Value of an environment variable */
  63.     FILE
  64.     *outfile;
  65.  
  66.     if( !header )
  67.     return;
  68.  
  69. #if MULTIPLEX
  70.     outfile = CURRTTY;
  71. #else
  72.     outfile = stdout;
  73. #endif
  74.  
  75. #if TERMCAP
  76.     /* Initialize termcap */
  77.     if( (value = getenv( "TERM" )) == (char *)0 )
  78.     error( 29 );        /* Bad termcap */
  79.     if( tgetent( bp, value ) <= 0 )
  80.     error( 29 );        /* Bad termcap */
  81.  
  82.     /* Get the number of lines on the screen */
  83.     END = tgetnum( "li" );
  84.  
  85.     /* Get the command strings */
  86.     (void)mygetstr( "cm", TGOTO, 1 );
  87.     (void)mygetstr( "so", STANDOUT, 0 );
  88.     (void)mygetstr( "se", STANDEND, 0 );
  89.     if( mygetstr( "cd", CLEAR, 0 ) == 0 )
  90.     (void)mygetstr( "cl", CLEAR, 1 );
  91.     (void)mygetstr( "ml", LOCK );
  92.     (void)mygetstr( "mu", NOLOCK );
  93. #endif
  94.  
  95. #if AMIGA
  96.     /* Set the screen dimensions for a standard console window */
  97.     END = 22;
  98. #else
  99.     /* See if the END is in the environment */
  100.     if( (value = getenv( "LINES" )) != (char *)0 )
  101.     END = atoi( value );
  102.  
  103.     if( END < 0 )
  104.     /* Assume a standard size terminal */
  105.     END = 23;
  106.     else
  107.     /* Last line is number of lines minus one. */
  108.     END--;
  109. #endif
  110.  
  111.     /* Go to the top of the screen */
  112. #if TERMCAP
  113.     fprintf( outfile, tgoto( TGOTO, 0, 0 ) );
  114. #endif
  115. #if ANSI
  116.     fprintf( outfile, TGOTO, 1, 1 );
  117. #endif
  118. #if HPTERM
  119.     fprintf( outfile, TGOTO, 0, 0 );
  120. #endif
  121.  
  122.     fputs( CLEAR, outfile );        /* Clear the screen */
  123.     fputs( STANDOUT, outfile );        /* First line inverse video */
  124.     fprintf( outfile, H_STR, "", 0, 0 );        /* Header line */
  125.     fputs( STANDEND, outfile );        /* End inverse video */
  126.     fputs( LOCK, outfile );        /* lock first line */
  127.  
  128.     /* Go to the end of the screen */
  129. #if TERMCAP
  130.     fprintf( outfile, tgoto( TGOTO, 0, END ) );
  131. #endif
  132. #if ANSI
  133.     fprintf( outfile, TGOTO, END+1, 1 );
  134. #endif
  135. #if HPTERM
  136.     fprintf( outfile, TGOTO, END, 0 );
  137. #endif
  138.  
  139.     fflush( outfile );
  140. }
  141.  
  142.  
  143. #if TERMCAP
  144. mygetstr( which, where, need )
  145. char
  146.     *which,
  147.     *where;
  148. int
  149.     need;
  150. {
  151.     int
  152.     retval;
  153.     char
  154.     *temp,
  155.     *save,
  156.     *tgetstr();
  157.  
  158.     save = where;
  159.     temp = tgetstr( which, &where );
  160.     if( temp == (char *)0 ) {
  161.     if( need ) {
  162.         error( 29 );            /* Bad termcap */
  163.         /*NOTREACHED*/
  164.     }
  165.     else {
  166.         *save = '\0';
  167.         retval = 0;
  168.     }
  169.     }
  170.     else {
  171.     *temp = '\0';
  172.     retval = 1;
  173.     }
  174.     return retval;
  175. }
  176. #endif
  177.  
  178.  
  179. write_head()
  180. {
  181.     FILE
  182.     *outfile;
  183.  
  184. #if MULTIPLEX
  185.     outfile = CURRTTY;
  186. #else
  187.     outfile = stdout;
  188. #endif
  189.  
  190.     if( !header )
  191.     return;
  192.  
  193.     assertargs( "$spec 9", 4 );        /* ($spec 9 str score moves)    */
  194.  
  195.     fputs( NOLOCK, stdout );        /* Turn off memory lock        */
  196.  
  197.     /* Go to the top of the screen */
  198. #if TERMCAP
  199.     fprintf( outfile, tgoto( TGOTO, 0, 0 ) );
  200. #endif
  201. #if ANSI
  202.     fprintf( outfile, TGOTO, 1, 1 );
  203. #endif
  204. #if HPTERM
  205.     fprintf( outfile, TGOTO, 0, 0 );
  206. #endif
  207.  
  208.     fputs( STANDOUT, outfile );        /* Inverse video        */
  209.     fprintf( outfile, H_STR, virtstr( ARG( 2 ) ), ARG( 3 ), ARG( 4 ) );
  210.     fputs( STANDEND, outfile );        /* Normal video            */
  211.     fputs( LOCK, outfile );        /* Lock the first line        */
  212.  
  213.     /* Go to the end of the screen */
  214. #if TERMCAP
  215.     fprintf( outfile, tgoto( TGOTO, 0, END ) );
  216. #endif
  217. #if ANSI
  218.     fprintf( outfile, TGOTO, END+1, 1 );
  219. #endif
  220. #if HPTERM
  221.     fprintf( outfile, TGOTO, END, 0 );
  222. #endif
  223.  
  224.     fflush( outfile );
  225. }
  226.  
  227.  
  228. head_term()
  229. {
  230. #if MULTIPLEX
  231.     fputs( NOLOCK, CURRTTY );
  232.     fflush( CURRTTY );
  233. #else
  234.     fputs( NOLOCK, stdout );        /* Turn off memory lock        */
  235.     fflush( stdout );
  236. #endif
  237. }
  238.  
  239. /*** EOF adlscrn.c ***/
  240.